package gogs_hook

import "jihulab.com/linksaas/proto-gen-go/events/events_gogs"

type CreateHook struct {
	Ref           string      `json:"ref"`
	RefType       string      `json:"ref_type"`
	Sha           string      `json:"sha"`
	DefaultBranch string      `json:"default_branch"`
	Repo          *Repository `json:"repository"`
	Sender        *User       `json:"sender"`
}

func (item *CreateHook) ToProtoBuf() *events_gogs.CreateEvent {
	ret := &events_gogs.CreateEvent{
		Ref:           item.Ref,
		RefType:       item.RefType,
		Sha:           item.Sha,
		DefaultBranch: item.DefaultBranch,
		Repo:          []*events_gogs.Repository{},
		Sender:        []*events_gogs.User{},
	}
	if item.Repo != nil {
		ret.Repo = append(ret.Repo, item.Repo.ToProtoBuf())
	}
	if item.Sender != nil {
		ret.Sender = append(ret.Sender, item.Sender.ToProtoBuf())
	}
	return ret
}
